package com.compomics.peptizer.gui.component;

import com.compomics.peptizer.gui.PeptizerGUI;
import com.intellij.uiDesigner.core.Spacer;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.net.URLClassLoader;

/**
 * This class is a
 */
public class StartPanel {
    private JPanel jpanContent;
    private JLabel lblPeptizerLogo;
    private JPanel jpanImage;
    private JPanel jpanStartTask;
    private JButton btnStartTask;
    private JButton btnHome;
    private JPanel jpanWebsite;
    private PeptizerGUI iPeptizerGUI;
    private String iPeptizerURL = "http://code.google.com/p/peptizer/";

    public StartPanel(PeptizerGUI aPeptizerGUI) {
        iPeptizerGUI = aPeptizerGUI;
        $$$setupUI$$$();
        btnStartTask.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent aActionEvent) {
                iPeptizerGUI.newTask();
            }
        });

        btnHome.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent aActionEvent) {
                HyperLinkLabel.HyperLinker.displayURL(iPeptizerURL);

            }
        });
        EmptyBorder lBorder = new EmptyBorder(0, 0, 0, 0);
        btnStartTask.setBorder(lBorder);
        btnHome.setBorder(lBorder);
    }

    private void createUIComponents() {

        URL urlStartImage = URLClassLoader.getSystemResource("image/IMAGE_start_panel.png");
        Image lStartImage = Toolkit.getDefaultToolkit().getImage(urlStartImage);
        JLabel lbl = new JLabel(new ImageIcon(lStartImage));
        lblPeptizerLogo = new HyperLinkLabel("", new ImageIcon(lStartImage), iPeptizerURL);

    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        createUIComponents();
        jpanContent = new JPanel();
        jpanContent.setLayout(new FormLayout("fill:d:grow", "center:d:noGrow,top:3dlu:noGrow,center:max(d;50px):noGrow,top:3dlu:noGrow,center:max(d;4px):noGrow,top:3dlu:noGrow,center:max(d;4px):noGrow"));
        jpanContent.setBackground(new Color(-1));
        jpanImage = new JPanel();
        jpanImage.setLayout(new FormLayout("fill:50px:noGrow,left:4dlu:noGrow,left:d:noGrow,left:4dlu:noGrow,fill:d:grow", "center:10px:noGrow,top:3dlu:noGrow,center:d:noGrow"));
        jpanImage.setBackground(new Color(-1));
        CellConstraints cc = new CellConstraints();
        jpanContent.add(jpanImage, cc.xy(1, 1));
        lblPeptizerLogo.setIcon(new ImageIcon(getClass().getResource("/image/IMAGE_start_panel.png")));
        lblPeptizerLogo.setText("");
        jpanImage.add(lblPeptizerLogo, cc.xy(3, 3, CellConstraints.CENTER, CellConstraints.DEFAULT));
        final Spacer spacer1 = new Spacer();
        jpanImage.add(spacer1, cc.xyw(1, 3, 2, CellConstraints.FILL, CellConstraints.DEFAULT));
        final Spacer spacer2 = new Spacer();
        jpanImage.add(spacer2, cc.xy(5, 3, CellConstraints.FILL, CellConstraints.DEFAULT));
        jpanStartTask = new JPanel();
        jpanStartTask.setLayout(new FormLayout("fill:max(d;50px):noGrow,left:4dlu:noGrow,fill:d:noGrow,left:4dlu:noGrow,fill:max(d;4px):noGrow", "center:d:noGrow"));
        jpanStartTask.setBackground(new Color(-1));
        jpanContent.add(jpanStartTask, cc.xy(1, 5));
        btnStartTask = new JButton();
        btnStartTask.setIcon(new ImageIcon(getClass().getResource("/image/ICON_newtask_large.png")));
        btnStartTask.setText("");
        jpanStartTask.add(btnStartTask, cc.xy(3, 1));
        final JLabel label1 = new JLabel();
        label1.setFont(new Font(label1.getFont().getName(), Font.ITALIC, label1.getFont().getSize()));
        label1.setText("start a new peptizer task");
        jpanStartTask.add(label1, cc.xy(5, 1));
        jpanWebsite = new JPanel();
        jpanWebsite.setLayout(new FormLayout("fill:max(d;50px):noGrow,left:4dlu:noGrow,fill:d:noGrow,left:4dlu:noGrow,fill:max(d;4px):noGrow", "center:d:noGrow"));
        jpanWebsite.setBackground(new Color(-1));
        jpanContent.add(jpanWebsite, cc.xy(1, 7));
        btnHome = new JButton();
        btnHome.setIcon(new ImageIcon(getClass().getResource("/image/ICON_home.png")));
        btnHome.setText("");
        jpanWebsite.add(btnHome, cc.xy(3, 1));
        final JLabel label2 = new JLabel();
        label2.setFont(new Font(label2.getFont().getName(), Font.ITALIC, label2.getFont().getSize()));
        label2.setText("go to peptizer website");
        jpanWebsite.add(label2, cc.xy(5, 1));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return jpanContent;
    }
}
